// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.commons.sql.data;

/**
 * DataSetRow, represents one row in a dataSet.
 * 
 * /** Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 2008-1-7 qiang.zhang $
 * 
 */
public class DataSetRow {

    private final Object[] pvalues;

    /**
     * Create new DataSetRow with columnCount values.
     * 
     * @param columnCount number of columns
     */
    public DataSetRow(int columnCount) {
        pvalues = new Object[columnCount];
    }

    private int rowIndex;

    /**
     * Create initialized dataSetRow.
     * 
     * @param values
     */
    public DataSetRow(String[] values) {
        pvalues = values;
    }

    /**
     * Returns value of given column.
     * 
     * @param column first column is 0
     */
    public Object getObjectValue(int column) {

        Object tmp = pvalues[column];
        if (tmp != null) {
            return tmp;
        }
        return "<null>"; //$NON-NLS-1$
    }

    /**
     * Set the value for a given column.
     * 
     * @param column first column is 0
     * @param value
     */
    public void setValue(int column, Object value) {
        pvalues[column] = value;
    }

    /**
     * @return number of columns in this row
     */
    public int length() {
        if (pvalues == null) {
            return 0;
        }
        return pvalues.length;
    }

    /**
     * Getter for pvalues.
     * 
     * @return the pvalues
     */
    public Object[] getPvalues() {
        return this.pvalues;
    }

    /**
     * Getter for rowIndex.
     * 
     * @return the rowIndex
     */
    public int getRowIndex() {
        return this.rowIndex;
    }

    /**
     * Sets the rowIndex.
     * 
     * @param rowIndex the rowIndex to set
     */
    public void setRowIndex(int rowIndex) {
        this.rowIndex = rowIndex;
    }
}
